package java8;

import java.time.*;
import java.time.format.DateTimeFormatter;

public class TimeTest {
    public static void main(String[] args) {
        LocalDate today = LocalDate.now();
        LocalDate day = LocalDate.of(2017, Month.JANUARY, 1);
        LocalTime time = LocalTime.now();
        LocalDateTime localDateTime = LocalDateTime.now();
        ZonedDateTime zonedDateTime = ZonedDateTime.now();
        LocalDateTime zoneDate = LocalDateTime.now(ZoneId.of("Asia/Oral"));
        //当前时间（年月日）
        System.out.println("当前时间（年月日）:" + today);
        //2017-01-01
        System.out.println("2017-01-01:" + day);
        //当前时间
        System.out.println("当前时间:" + time);
        //完整的日期时间
        System.out.println("完整的日期时间:" + localDateTime);
        //当前时区时间
        System.out.println("当前时区时间:" + zonedDateTime);
        //指定时区的时间
        System.out.println("指定时区的时间:" + zoneDate);


        //加减测试
        System.out.println("增加2天：" + today.plusDays(2));
        System.out.println("增加2周：" + today.plusWeeks(2));
        System.out.println("增加2月：" + today.plusMonths(2));
        System.out.println("增加2年：" + today.plusYears(2));

        //格式化
        System.out.println("格式化后的时间：" + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")));

    }
}
